package com.gtw.modules.sys.controller;

import com.gtw.common.utils.PageUtils;
import com.gtw.common.utils.Query;
import com.gtw.common.utils.R;
import com.gtw.modules.entity.TbBankCard;
import com.gtw.modules.sys.service.TbBankCardService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/** 银行账户Controller
 * Created by wuye on 2018/3/26.
 */
@RestController
@RequestMapping("/sys/bankcard")
public class SysTbBankCardController {

    @Autowired
    private TbBankCardService bankcardService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:bankcard:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<TbBankCard> bankcardList = bankcardService.queryList(query);
        int total = bankcardService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(bankcardList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:bankcard:info")
    public R info(@PathVariable("id") Integer id){
        TbBankCard bankcard = bankcardService.queryObject(id);

        return R.ok().put("bankcard", bankcard);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:bankcard:save")
    public R save(@RequestBody TbBankCard bankcard){
        bankcardService.save(bankcard);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:bankcard:update")
    public R update(@RequestBody TbBankCard bankcard){
        bankcardService.update(bankcard);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:bankcard:delete")
    public R delete(@RequestBody Integer[] ids){
        bankcardService.deleteBatch(ids);

        return R.ok();
    }
}
